<template>
  <div id="ccexception"
       v-loading="loading">
    <v-tableTitle :btnConfig="btnConfig"
                  :tableSelectData="tableSelectData"
                  :title="$t('work.exception')"
                  @del="del"
                  @newCreate="newCreate"
                  @closeParentTask="closeParentTask"></v-tableTitle>
    <v-table :hasEdit="false"
             :pageSize="pageSize"
             :page="page"
             :tableConfig="tableConfig"
             :tableData="tableData"
             :total="total"
             @findData="getTableData"
             @getTableData="getTableData"
             @searhData="searhData"
             @selectData="selectData"
             @upData="getTableData"
             ref="table"></v-table>
  </div>
</template>

<script type="text/ecmascript-6">
import tableTitle from "commons/TableTitle";
import table from "commons/Table";
import baseMixin from "@/mixins/BaseMixin";
import config from "./Config";
import bus from "../../../../bus/bus"

export default {
  name: "ccexception",
  mixins: [baseMixin, config],
  data () {
    return {
      loading: false,
      tableConfig: [
        {
          label: this.$t('home.subkey'),
          prop: "subkey",
          input: "input",
        },
        {
          label: this.$t('config.area'),
          prop: "regional",
          input: "input"
        },
        {
          label: this.$t('config.area'),
          prop: "district",
          input: "input",
        },
        {
          label: this.$t('config.loc'),
          prop: "loc",
          input: "input",
        },
        {
          label: this.$t('config.sku'),
          prop: "sku",
          input: "input",
        },
        {
          label: this.$t('in.lpn'),
          prop: "pltno",
          input: "input",
        },
        {
          label: this.$t('home.qty'),
          prop: "qty",
          input: "input",
        },
        {
          label: this.$t('home.inventory'),
          prop: "inventory",
          input: "input",
        },
        {
          label: this.$t('common.status'),
          prop: "status",
          input: "select",
          options: this.getOptions("codelkup/LADYCCSTATUS")
        },
      ],
      tableData: [],
      pageSize: 10,
      page: 1,
      total: 0,
      tableSelectData: [],
      tableSearhData: {},
    };
  },
  computed: {
    btnConfig () {
      return [
        { label: this.$t('common.create'), certigier: this.newStatus||!this.btnPermNameList.includes('WM06040401'), invalid: "newCreate" },
        { label: this.$t('common.delete'), certigier: this.deleteStatus||!this.btnPermNameList.includes('WM06040402'), disabled: true, invalid: "del" },
        { label: this.$t('home.closeParentTask'), certigier: this.closeParentTaskStatus||!this.btnPermNameList.includes('WM06040403'), disabled: true, invalid: "closeParentTask" },
      ]
    }
  },
  created () {
  },
  methods: {
    async closeParentTask (data) {
      try {
        let res = await this.$api.post(`/rtx_ccexceptionAction/CLOSECCEXCEPTION`, data);
        
          this.$message.success(res.returnMgr);
          let page = sessionStorage.getItem('page');
          this.getTableData(page, this.tableSearhData);
          
        
      } catch (e) {
        this.$message.error(e);
      }
    },
    //新建
    async newCreate () {
      this.$store.commit("setNewFlag", true);
      this.$router.push({ name: 'ccexceptionDeawer' });
    },
    //选中的内容
    selectData (data) {
      this.tableSelectData = data;
    },
    //删除
    async del (data) {
      let flag = true
      data.forEach(element => {
        if (element.status != '10') {
          this.$message.error(this.$t('msg.msg70'))
          flag = false
        }
      });
      if (flag) {
        try {
          let res = await this.$api.post(`/deleteRtx_ccexception`, data);
          
            this.$message.success(res.returnMgr);
            let page = sessionStorage.getItem('page');
            this.getTableData(page, this.tableSearhData);
            
        } catch (e) {
          this.$message.error(e);
        }
      }

    },
    async getTableData (page, data) {
      try {
        this.loading = true;
        let res = await this.$api.post(`/queryRtx_ccexceptionList/${page}`, data);
        
          this.tableData = res.page.list;
          this.page = res.page.curPage;
          this.pageSize = res.page.pageSize;
          this.total = res.page.total;
        
      } catch (e) {
        this.$message.error(e);
      } finally {
        this.loading = false;
      }
    },
    //搜索的值
    searhData (data, up) {
      if (!up) {
        this.tableSearhData = data;
      } else {
        this.tableSearhData = data;
        this.getTableData(1, this.tableSearhData);
      }
    },
  },
  mounted () {
    
    this.$store.commit("setSkip", {});
    this.$store.commit("setNewFlag", false);
    this.$store.commit("setRouteData", {});
    this.getTableData(1, {});
  },
  watch: {
    tableSelectData (data) {
      if (this.permissionStatus) {
        if (data.length > 0) {
          this.deleteStatus = this.closeStatus = false;
        } else {
          this.deleteStatus = this.closeStatus = true;
        }
      }
    }
  },
  components: {
    "v-tableTitle": tableTitle,
    "v-table": table,
  }
};
</script>

<style scoped>
#ccexception {
  width: 100%;
  height: 99%;
  padding-top: 6px;
}
</style>
